#ifndef CCTREECTRL
#define CCTREECTRL

#include <wx/treectrl.h>

#include <queue>

#include "parser/parser.h"
#include "parser/token.h"
class wxPoint;
class wxSize;
class wxWindow;

class Token;

enum SpecialFolder {
  sfToken   = 0x0001,
  sfRoot    = 0x0002,
  sfGFuncs  = 0x0004,
  sfGVars   = 0x0008,
  sfPreproc = 0x0010,
  sfTypedef = 0x0020,
  sfBase    = 0x0040,
  sfDerived = 0x0080,
  sfMacro   = 0x0100
};

class CCTreeCtrlData : public wxTreeItemData {
  public:
    CCTreeCtrlData( SpecialFolder sf = sfToken, Token* token = 0,
                    short int kindMask = 0xffff, int parentIdx = -1 );

    Token*        m_Token;
    short int     m_KindMask;
    SpecialFolder m_SpecialFolder;
    int           m_TokenIndex;
    TokenKind     m_TokenKind;
    wxString      m_TokenName;
    int           m_ParentIndex;
    unsigned long m_Ticket;
};

class CCTreeCtrlExpandedItemData {
  public:
    CCTreeCtrlExpandedItemData( const CCTreeCtrlData* data, const int level );

    int   GetLevel() const          { return m_Level; }
    const CCTreeCtrlData& GetData() { return m_Data;  }
  private:
    CCTreeCtrlData m_Data;
    int            m_Level;
};

typedef std::deque<CCTreeCtrlExpandedItemData> ExpandedItemVect;
typedef std::deque<CCTreeCtrlData>             SelectedItemPath;

class CCTreeCtrl : public wxTreeCtrl {
  public:
    CCTreeCtrl();
    CCTreeCtrl( wxWindow* parent, const wxWindowID id, const wxPoint& pos,
                const wxSize& size, long style );

    void SetCompareFunction( const BrowserSortType type );
    void RemoveDoubles( const wxTreeItemId& parent );

  protected:
    static int CBAlphabetCompare( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );
    static int CBKindCompare( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );
    static int CBScopeCompare( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );
    static int CBLineCompare( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );
    static int CBNoCompare( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );

    int OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 );
    int ( *Compare )( CCTreeCtrlData* lhs, CCTreeCtrlData* rhs );

    DECLARE_DYNAMIC_CLASS( CCTreeCtrl )
};

#endif
